package com.itheima.sfbx.insurance.handler.impl;

import com.itheima.sfbx.insurance.dto.DoInsureVo;
import com.itheima.sfbx.insurance.handler.InsureHandler;
import com.itheima.sfbx.insurance.pojo.CustomerRelation;
import com.itheima.sfbx.insurance.service.ICustomerRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @ClassName AccidentInsureHandler.java
 * @Description 保障型意外类：保险投保、创建订单、保费计算
 */
@Service
public class AccidentInsureHandler extends SafeguardInsureHandler implements InsureHandler {

    @Autowired
    private ICustomerRelationService customerRelationService;

    @Override
    public String doPremium(DoInsureVo doInsureVo) {
        if (doInsureVo.getCustomerRelationIds() != null) {
            //根据被投保人ID查询投保人信息
            String customerRelationId = doInsureVo.getCustomerRelationIds().get(0);
            CustomerRelation customerRelation = customerRelationService.getById(customerRelationId);
            if (customerRelation.getIncome().compareTo(new BigDecimal("1000000.0")) > 0 || customerRelation.getIncome() == null) {
                throw new RuntimeException("投保人可能是杀手，不能投保");
            }
        }
        return super.doPremium(doInsureVo);
    }
}
